package wt.hpad.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * Fragment基类
 * Created by wt on 11.18.
 */
public abstract class BaseFragment extends Fragment {

    public Activity baseActivity;
    public View mRootView;

    // fragment创建
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseActivity = getActivity();
    }

    // fragment布局完成
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = initViews();
        return mRootView;
    }


    // fragment所在activity创建完成
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    /**
     * 初始化数据不是必须的,
     * 可能该Fragment仅仅只是作为展示,
     * 所以就不做成抽象函数
     */
    public void initData() {
    }

    /**
     * 初始化布局是必须的
     */
    public abstract View initViews();

    @Override
    public void onDestroy() {
        super.onDestroy();
        mRootView.destroyDrawingCache();
        mRootView = null;
    }
}
